package com.novabluetooth.adapter;

import com.health.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 主菜单布局adapter【体检】
 */
public class SBCLMenuGridAdapter extends BaseAdapter {
	private int[] imgs;
	private String[] names;
	private int[] colors;
	private Context mContext;


	public SBCLMenuGridAdapter(Context mContext) {
		this.mContext = mContext;

// 		imgs = new int[] {R.drawable.sbcl_tiwen, R.drawable.sbcl_xueyang, R.drawable.sbcl_xuetang,R.drawable.sbcl_tizhong,
//				R.drawable.sbcl_xueya,R.drawable.sbcl_xuetang, R.drawable.sbcl_xuezhi, R.drawable.sbcl_tizhong,
//				R.drawable.sbcl_tizhong,R.drawable.sbcl_niaochanggui,R.drawable.sbcl_trip,
//				R.drawable.sbcl_xindian,R.drawable.sbcl_tiwen,R.drawable.sbcl_xueya};
//		names = new String[] {  "体温","血氧","血糖仪","体脂秤","血压计", "血糖(三诺)", "血脂","体重","体重秤",
//				"尿常规", "血红蛋白", "心电","额温枪","血压"};

		imgs = new int[] {R.drawable.sbcl_tiwen, R.drawable.sbcl_xueyang, R.drawable.sbcl_xuetang,
				R.drawable.sbcl_tizhong, R.drawable.sbcl_xueya,R.drawable.sbcl_xuetang,
				R.drawable.sbcl_tizhong, R.drawable.sbcl_xindian,R.drawable.sbcl_tiwen,
				R.drawable.sbcl_xueya,R.drawable.sbcl_niaochanggui,R.drawable.sbcl_tiwen
				,R.drawable.sbcl_xuetang,R.drawable.sbcl_xuetang,R.drawable.sbcl_xuetang,
				R.drawable.sbcl_xueya};
		// 6 7 9 10 "血糖(三诺)"
		names = new String[] {  "体温","血氧","血糖仪","体脂秤","血压计", "血糖",
				"体重秤", "心电","额温枪","血压","尿常规","体温计","血脂","血糖仪百捷老版本","脉搏波血压4"};

		//,0xff71B57C, 0xff71B57C, 0xff71B57C
		colors = new int[] { 0xff71B57C,0xff71B57C, 0xff71B57C, 0xff71B57C,0xff71B57C,
				0xff71B57C, 0xff71B57C, 0xff71B57C, 0xff71B57C, 0xff71B57C,0xff71B57C,0xff71B57C
				,0xff71B57C,0xff71B57C,0xff71B57C};
	}

	@Override
	public int getCount() {
		return names.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder vh;
		convertView = LayoutInflater.from(mContext).inflate(R.layout.bluetooth_sbcl_griditem, null);
		vh = new ViewHolder();
		vh.img = (ImageView) convertView.findViewById(R.id.norm_img);
		vh.nameText = (TextView) convertView.findViewById(R.id.norm_name);
		vh.tv_brand = (TextView) convertView.findViewById(R.id.tv_brand);
//		if (convertView == null) {
//			convertView = LayoutInflater.from(mContext).inflate(R.layout.bluetooth_sbcl_griditem, null);
//			vh = new ViewHolder();
//			vh.img = (ImageView) convertView.findViewById(R.id.norm_img);
//			vh.nameText = (TextView) convertView.findViewById(R.id.norm_name);
//			vh.tv_brand = (TextView) convertView.findViewById(R.id.tv_brand);
//			int drawableID = imgs[position];
//			String name = names[position];
//			int color = colors[position];
////			findView(vh, convertView, drawableID, name, color,position);
//			convertView.setTag(R.id.TAG_VIEWHOLDER, vh);
//		} else{
//			vh = (ViewHolder) convertView.getTag(R.id.TAG_VIEWHOLDER);
//		}

		setData(vh, convertView, position);

		return convertView;
	}

	/**
	 * 赋值
	 *
	 * @param h
	 * @param v
	 * @param position
	 * @author 王婷婷
	 * @date 2015年12月3日 上午10:24:28
	 */
	private void setData(ViewHolder h, View v, int position) {
		h.img.setImageResource(imgs[position]);
		h.nameText.setText(names[position]);
		Log.e("xiaoxin", "setData: " + position + "    " + names[position]);
		if(names[position].equals("体温")){
			h.tv_brand.setVisibility(View.VISIBLE);
			h.tv_brand.setText("(和泰达)");
		}
		if(names[position].equals("血糖仪")){
			h.tv_brand.setVisibility(View.VISIBLE);
			h.tv_brand.setText("(百捷)");
		}
		if(names[position].equals("体脂秤")){
			h.tv_brand.setVisibility(View.VISIBLE);
			h.tv_brand.setText("(轻加)");
		}
		if(names[position].equals("血压计")){
			h.tv_brand.setVisibility(View.VISIBLE);
			h.tv_brand.setText("(鱼跃)");
		}
		if(names[position].equals("额温枪")){
			h.tv_brand.setVisibility(View.VISIBLE);
			h.tv_brand.setText("(倍泰)");
		}
		if(names[position].equals("血压")){
			h.tv_brand.setVisibility(View.VISIBLE);
			h.tv_brand.setText("(脉搏波)");
		}

		if(names[position].equals("体重秤")){
			h.tv_brand.setVisibility(View.VISIBLE);
			h.tv_brand.setText("(倍泰)");
		}
		if(names[position].equals("心电")){
			h.tv_brand.setVisibility(View.GONE);
			h.tv_brand.setText("");
		}
		if(names[position].equals("血红蛋白")){
			h.tv_brand.setVisibility(View.GONE);
			h.tv_brand.setText("");
		}
		if(names[position].equals("尿常规")){
			h.tv_brand.setVisibility(View.GONE);
			h.tv_brand.setText("");
		}
		if(names[position].equals("体重")){
			h.tv_brand.setVisibility(View.GONE);
			h.tv_brand.setText("");
		}
		if(names[position].equals("血脂")){
//			h.tv_brand.setVisibility(View.GONE);
//			h.tv_brand.setText("");
			h.tv_brand.setVisibility(View.VISIBLE);
			h.tv_brand.setText("(e家医护)");
		}

		if(names[position].equals("血糖")){
			h.tv_brand.setVisibility(View.VISIBLE);
			h.tv_brand.setText("(三诺)");
		}

		if(names[position].equals("尿常规")){
			h.tv_brand.setVisibility(View.VISIBLE);
			h.tv_brand.setText("(恩普生)");
		}

		if(names[position].equals("体温计")){
			h.tv_brand.setVisibility(View.VISIBLE);
			h.tv_brand.setText("(爱奥乐)");
		}

		if(names[position].equals("血糖仪百捷老版本")){
			h.nameText.setText("血糖仪");
			h.tv_brand.setVisibility(View.VISIBLE);
			h.tv_brand.setText("(百捷老版)");
		}


		if(names[position].equals("脉搏波血压4")){
			h.nameText.setText("血压");
			h.tv_brand.setVisibility(View.VISIBLE);
			h.tv_brand.setText("(脉搏波4.0)");
		}

	}

//	private void findView(ViewHolder h, View v, int drawableID, String name, int color,int position) {
//		h.img = (ImageView) v.findViewById(R.id.norm_img);
//		h.nameText = (TextView) v.findViewById(R.id.norm_name);
//
////		h.img.setImageResource(drawableID);
////		h.nameText.setText(name);
////		h.nameText.setTextColor(color);

//	}

	private static class ViewHolder {
		ImageView img;
		TextView nameText,tv_brand;
	}

}
